# Adogs
# 时间: 2021/7/17 15:13
import pygame
from actor.walk_soldier import WalkSoldier
from actor import DirShootByImage
from actor import ShootDir
from actor import WalkDir


class ShootSoldier(WalkSoldier):
    """
    射击战士类
    继承行走战士类
    方法：
    1.__init__(walk_image_path, shoot_image_path, x, y, name, hp)
    2.run(down_flag, key_list, obstacle_group)
    3.draw(surface, x, y)
    """
    shoot_image_wide = 100
    shoot_image_high = 100  # 射击图片的宽高

    def __init__(self, walk_image_path: str, shoot_image_path: str, x: int, y: int, name: str, hp: int):
        """
        初始化函数
        :param walk_image_path: 人物行走图片路径
        :param shoot_image_path: 人物射击图片路径
        :param x: 人物x坐标
        :param y: 人物y坐标
        :param name: 人物名字
        :param hp:  人物血量
        """
        super(ShootSoldier, self).__init__(walk_image_path, x, y, name, hp)  # 调用基类函数
        self.shoot_action = DirShootByImage(shoot_image_path, self.shoot_image_wide, self.shoot_image_high, True)
        self.shoot_action.set_dir(ShootDir.not_shoot)   # 初始化定义为不射击

    def run(self, down_flag, key_list, obstacle_group):
        """
        人物运动函数
        :param down_flag: 判断是否点击按键
        :param key_list: 判断是否有键被按下
        :param obstacle_group: 障碍物组
        :return: 无返回值
        """
        self.shoot_action.set_dir(ShootDir.not_shoot)
        super(ShootSoldier, self).run(down_flag, key_list)  # 调用基类的行走方法

        if down_flag:   # 人物射击方法
            if key_list[pygame.K_u]:
                self.shoot_action.set_dir(ShootDir.left_up)
            elif key_list[pygame.K_o]:
                self.shoot_action.set_dir(ShootDir.right_up)
            elif key_list[pygame.K_j]:
                self.shoot_action.set_dir(ShootDir.left_down)
            elif key_list[pygame.K_l]:
                self.shoot_action.set_dir(ShootDir.right_down)
            elif key_list[pygame.K_i]:
                self.shoot_action.set_dir(ShootDir.up)
                self.walk_action.set_dir(WalkDir.on)
            elif key_list[pygame.K_k]:
                self.shoot_action.set_dir(ShootDir.down)
                self.walk_action.set_dir(WalkDir.down)

    def draw(self, surface: pygame.Surface, x: int, y: int):
        """
        人物绘制函数
        :param surface: 当前绘制屏幕
        :param x: 屏幕相对x坐标
        :param y: 屏幕相对y坐标
        :return: 无返回值
        """
        if self.shoot_action.shoot_dir == ShootDir.not_shoot:
            '''如果没有射击就调用基类的绘制方法'''
            super(ShootSoldier, self).draw(surface, x, y)

            """如果射击了就另写绘制函数"""
        elif self.shoot_action.shoot_dir == ShootDir.down:
            current_img = self.walk_action.get_image()
            surface.blit(current_img, (self.pos_x - x, self.pos_y - y))
            current_img = self.shoot_action.get_image()
            surface.blit(current_img, (self.pos_x - 30 - x, self.pos_y - 5 - y))
        elif self.shoot_action.shoot_dir == ShootDir.up:
            current_img = self.shoot_action.get_image()
            surface.blit(current_img, (self.pos_x - x, self.pos_y - y))
            current_img = self.walk_action.get_image()
            surface.blit(current_img, (self.pos_x - x, self.pos_y - y))
        else:
            current_img = self.shoot_action.get_image()
            surface.blit(current_img, (self.pos_x - x, self.pos_y - y))
